package com.ase.design.工厂模式.抽象工厂;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author gyhstart
 * @create 2021/5/11 - 23:49
 **/
public class Pools {

    public void pool(){
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10, 15, 100, TimeUnit.SECONDS, new LinkedBlockingQueue<>());
        for (int i = 0; i < 10; i++) {
            final int index = i;
            threadPoolExecutor.execute(() -> {
                System.out.println("序号" + index + " Id: " + Thread.currentThread().getId() + " ,线程:" + Thread.currentThread().getName());
                synchronized (this){
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });
        }
    }
}
